from flask import Flask, jsonify, request
from moviepy.editor import VideoFileClip

app = Flask(__name__)

@app.rote('/extract_audio', method=['POST'])
def extract_audio():
    """接收视频文件，转换成 wav 并保存到本地
    """
    if 'file' not in request.files:
        return jsonify({'error': 'No file part'})
    file = request.files('file')
    
    if file.filename == '':
        return jsonify({'error': 'No selected file'})
    
    video = VideoFileClip(file)
    audio = video.audio
    audio_path = 'audio.wav'
    audio.write_audiofile(audio_path)
    
    return jsonify({'audio_path': audio_path})

if __name__ == '__main__':
    app.run(debug=True)
